<?=view('header.html')?>

<body class="layui-view-body bgwhite">
    <div class="layui-content" style="margin-bottom: 0px; padding-bottom: 0px;">
        <div class="layui-row">
            <div class="layui-cards">
                <div class="layui-card-body">
                    <form class="layui-form" method="post" name="myform" id="myform">

                        <div class="layui-form-item">
                            <label class="layui-form-label">用户组:</label>
                            <div class="layui-input-inline">
                                <div class="layui-form-mid layui-word-aux"><?=$group['name'] ?? '未知!'?></div>
                                <input type="hidden" value="<?=isset($data['groupid']) ? $data['groupid'] : $groupid;?>" readonly name="data[groupid]">
                            </div>
                        </div>


                        <div class="layui-form-item">
                            <label class="layui-form-label">名称:</label>
                            <div class="layui-input-inline">
                                <input type="text" name="data[name]" value="<?=isset($data['name']) ? $data['name'] : ''?>" id="ams_name" lay-verify="required" placeholder="请输入等级名称" autocomplete="off"
                                    class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">售价:</label>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="text" name="data[price]" value="<?=isset($data['price']) ? $data['price'] : ''?>" placeholder="价格" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">星级:</label>
                            <div class="layui-input-block">
                                <div class="stars" id="starsdiv"></div>
                                <div class="layui-inline"><a class="layui-btn layui-btn-xs" id="reststars">清零星级</a></div>
                                <input type="hidden" value="<?=$data['stars'] ?? 5?>" id="stars" name="data[stars]" placeholder="星级" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">说明:</label>
                            <div class="layui-input-inline">
                                <textarea name="data[content]" value="<?=$data['content'] ?? ''?>" class="layui-textarea" placeholder="说明"></textarea>
                            </div>

                        </div>

                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button type="button" class="layui-btn layui-btn-blue" lay-submit="" lay-filter="ams_submit">提交保存</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <?=view('footer.html')?>
    <script type="text/javascript">

        layui.use(['layer', 'form', 'rate'], function () {
            var layer = layui.layer,
                rate = layui.rate,
                form = layui.form;

            var stars = $("#stars").val();
            rate.render({
                elem: '#starsdiv'
                , value: stars //初始值
                , text: false //开启文本
                , choose: function (value) {
                    $("#stars").val(value);
                }
            });

            $('#reststars').click(function () {
                $("#stars").val(0);
                rate.render({ elem: '#starsdiv', value: 0 });
            })


            var url = window.location.href;

            //提交
            form.on('submit(ams_submit)', function (data) {
                $.post(url, data.field, function (res) {
                    if (res.code == 0) {
                        layer.msg(res.msg, { time: 1500 }, function () {
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index);
                        });
                    } else {
                        layer.msg(res.msg);
                    }
                }, 'json');
                return false;
            });

        });

    </script>
</body>

</html>